﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StackTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack stack = new Stack();


            Console.WriteLine("开始放球");

            stack.Push("1号乒乓球");
            stack.Push("2号乒乓球");
            stack.Push("3号乒乓球");
            stack.Push("4号乒乓球");
            stack.Push("5号乒乓球");
            stack.Push("6号乒乓球");

            Console.WriteLine("遍历一下stack集合");
            OutValues(stack);

            var st = stack.Peek();

            Console.WriteLine("第一个出来的球是{0}", st);


            Console.WriteLine("试试使用GetEnumerator的方法遍历stack集合");
            IEnumerator ien = stack.GetEnumerator();
            while (ien.MoveNext())
            {
                Console.WriteLine(ien.Current);
            }


            bool b = stack.Contains("5号乒乓球");
            if (b)
            {
                Console.WriteLine("存在5号乒乓球");
            }
            else
            {
                Console.WriteLine("不存在5号乒乓球");
            }


            Console.WriteLine("移除式遍历");
            while (stack.Count != 0)
            {
                Console.WriteLine("开始拿球{0}", stack.Pop());
            }


            Console.ReadKey();

        }

        static void OutValues(ICollection collection)
        {
            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }
        }
    }
}
